const jwt = require("jsonwebtoken");
const jwtAuth = require("koa-jwt");
const secret = "thewall";
const router = require('koa-router')();
router.post('/login', async (ctx) => {
    const { body } = ctx.request;
    let userinfo = body.user
    ctx.body = {
        msg: '登陆成功',
        user: userinfo,
        token: jwt.sign(
            {
                data: userinfo,
                exp: Math.floor(Date.now() / 1000) + 60 * 60 //一小时后过期 
            },
            secret
        )
    }
})

router.post('/getuser', jwtAuth({ secret }), async (ctx) => {
    ctx.body = {
        message:'success',
    }
})
router.get('/', function (req, res) {
    res.sendFile(__dirname + '/index.html');
})

module.exports = router